/*
 *  MTouchware_touch.c
 *
 *  This code helps using the touch structures to implement Mtouchware services.
 *
 *  Copyright (C) 2010 LIMSI-CNRS (Orsay-France) and EFREI (Paris-France)
 *
 *  Authors: Rami Ajaj, Nicolas Flasque and Frederic Vernier.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  $Id$
 */

#include <string.h>
#include <stdio.h>
#include "MTouchware_touch.h"

char built_in_formats[MT_NB_FORMATS][20]=
{
    "/tuio/2Dobj", "/tuio/25Dobj", "/tuio/3Dobj",
    "/tuio/2Dblb", "/tuio/25Dblb", "/tuio/3Dblb",
    "/tuio/2Dcur", "/tuio/25Dcur", "/tuio/3Dcur",
    "/tuio/custom"
};

char *get_path_string(t_tuio_format f)
{
    return built_in_formats[f];
}

t_tuio_format get_tuio_format_from_string(const char *format)
{

    int i=0;
    int found = 0;

    while ((i<MT_NB_FORMATS) && (!found))
    {
        if (!strcmp(format,built_in_formats[i]))
        {
            found = 1;
        }
        else
        {
            i++;
        }
    }

    if (found)
    {
        return i;
    }
    else
    {
        return -1;
    }
}


void initValues(p_touch_values pval)
{
    pval->session_id = -1;
    pval->object_id = -1;
    pval->where.x = pval->where.y = pval->where.z = 0.0;
    pval->angle.a = pval->angle.b = pval->angle.c = 0.0;
    pval->dims.w = pval->dims.h = pval->dims.d = 0.0;
    pval->speed.sx = pval->speed.sy = pval->speed.sz = 0.0;
    pval->rotationVelocity.rvx = pval->rotationVelocity.rvy = pval->rotationVelocity.rvz = 0.0;
    pval->area = pval->volume = 0.0;
    pval->motionAccel = pval->rotationAccel = 0.0;

    return;
}

void displayValues(p_touch_values pval)
{
    printf("                                             sessionID = %ld\n",pval->session_id);
    printf("                                             objectID  = %ld\n",pval->object_id);
    printf("                                             where     = %lf %lf %lf\n",pval->where.x,pval->where.y,pval->where.z);
    printf("                                             angle     = %lf %lf %lf\n",pval->angle.a,pval->angle.b,pval->angle.c);
    printf("                                             speed     = %lf %lf %lf\n",pval->speed.sx,pval->speed.sy,pval->speed.sz);
    printf("                                             dims      = %lf %lf %lf\n",pval->dims.w,pval->dims.h,pval->dims.d);
    printf("                                             rotvel    = %lf %lf %lf\n",pval->rotationVelocity.rvx,pval->rotationVelocity.rvy,pval->rotationVelocity.rvz);
    printf("                                             area / volume  = %lf %lf\n",pval->area, pval->volume);
    printf("                                             accel / raccel = %lf %lf\n",pval->motionAccel, pval->rotationAccel);
}
